/**
 * 
 */
package No401_500.No461_470.IslandPerimeter_463;
/** 
 * @author  作者 E-mail: ttljtw@qq.com
 * @date 创建时间：2017年2月20日 下午7:11:38 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */
/**
 * @author 李敬
 *
 */
public class Solution {
    public int islandPerimeter(int[][] grid) {
    	int islands = 0,
    		elseLines = 0;
    	int col = grid[0].length;
    	System.out.println(col);
    	int row = grid.length;////////第一遍出错之处
    	System.out.println(row);
        for(int i = 0 ; i < row ; i++){
            for (int j = 0; j < col ;j++){
            	if (grid[i][j] == 1) {
                	islands++;
				}
            	if ((j!=0)&&(grid[i][j-1] == 1)) {
					elseLines++;
				}
            	if((i!=0)&&(grid[i-1][j] == 1)){
            		elseLines++;
            	}
            	if ((j!=col-1)&&(grid[i][j+1] == 1)) {
            		elseLines++;
				}
            	if((i!=row-1)&&(grid[i+1][j] == 1)){
            		elseLines++;
            	}
            	System.out.println(islands+" "+elseLines);
            }
        }
        return islands*4-elseLines;
    }

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[][] grid = {{0,1,0,0},{1,1,1,0},{0,1,0,0},{1,1,0,0}};
		Solution solution = new Solution();
		solution.islandPerimeter(grid);
	}

}
